/*
 * savecheque.java
 *
 * Created on March 4, 2007, 9:44 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package eCheque;

import java.io.*;

/**
 * 
 * @author Basel
 */
public class EChequeIO {

	public void savecheque(ECheque obj, String filename) throws IOException {
		FileOutputStream fileOutputStream = null;
		ObjectOutputStream objectOutputStream = null;
		try {
			File file = new File(filename);
			fileOutputStream = new FileOutputStream(file);
			objectOutputStream = new ObjectOutputStream(fileOutputStream);
			objectOutputStream.writeObject(obj);
		} finally {
			EChequeUtils.safeClose(fileOutputStream);
			EChequeUtils.safeClose(objectOutputStream);
		}
	}

	public ECheque readcheque(String filename) throws IOException,
			ClassNotFoundException {
		FileInputStream fileInputStream = null;
		ObjectInputStream objectInputStream = null;
		
		try {
			fileInputStream = new FileInputStream(filename);
			objectInputStream = new ObjectInputStream(fileInputStream);
			return (ECheque)objectInputStream.readObject();
		} finally {
			EChequeUtils.safeClose(fileInputStream);
			EChequeUtils.safeClose(objectInputStream);
		}
	}

	/** Creates a new instance of savecheque */
	public EChequeIO() {

	}

}
